//
//  HNSH_ShopApplyInputCell.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/3/4.
//

#import "HNSH_ShopApplyInputCell.h"

@interface HNSH_ShopApplyInputCell ()

/* titleLabel */
@property (nonatomic, strong) UILabel *titleLabel;
/* lineView */
@property (nonatomic, strong) UIView *lineView;

@end

@implementation HNSH_ShopApplyInputCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor appWhiteLabelColor];
        [self configView];
    }
    return self;
}

- (void)setPlaceholder:(NSString *)placeholder {
    _placeholder = placeholder;
    self.textField.placeholder = placeholder;
    NSMutableAttributedString *placeholderString = [[NSMutableAttributedString alloc] initWithString:self.textField.placeholder];
    [placeholderString addAttribute:NSForegroundColorAttributeName
                            value:[UIColor appGray666LabelColor]
                            range:NSMakeRange(0, self.textField.placeholder.length)];
    [placeholderString addAttribute:NSFontAttributeName
                            value:[UIFont systemFontOfSize:14]
                            range:NSMakeRange(0, self.textField.placeholder.length)];
    self.textField.attributedPlaceholder = placeholderString;
}

- (void)setTitle:(NSString *)title {
    _title = title;
    self.titleLabel.text = title;
}

- (void)configView {
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.textField];
    [self.contentView addSubview:self.lineView];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.left.mas_equalTo(20);
        make.height.mas_equalTo(50).priorityHigh();
    }];
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.right.mas_equalTo(-16);
        make.width.mas_equalTo(200);
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(1);
    }];
    
    WeakSelf(weakSelf);
    [[self.textField rac_signalForControlEvents:UIControlEventEditingChanged] subscribeNext:^(__kindof UIControl * _Nullable x) {
        UITextField *field = x;
        if (weakSelf.inputBlock) {
            weakSelf.inputBlock(field.text);
        }
    }];
}

#pragma mark lazy
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.textColor = [UIColor appBlackLabelColor];
        _titleLabel.font = [UIFont boldSystemFontOfSize:14];
    }
    return _titleLabel;;
}

- (UITextField *)textField {
    if (!_textField) {
        _textField = [[UITextField alloc]init];
        _textField.textColor = [UIColor appBlackLabelColor];
        _textField.font = [UIFont boldSystemFontOfSize:14];
        _textField.textAlignment = NSTextAlignmentRight;
    }
    return _textField;
}

- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = [UIColor colorWithHexString:@"#EDEDED"];
    }
    return _lineView;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
